<template>
  <div class="layout-left-module-item" v-if="hotJson.links.length">
    <div class="layout-left-module-item-title">
      {{ hotJson.title }}
      <el-icon @click="refresh">
        <refresh-right />
      </el-icon>
    </div>
    <div class="layout-hot-search-result" v-if="hotJson.links.length">
      <div class="hot-search-result-link" v-for="link in hotJson.links" :key="link.keyword">
        <span :class="['badge', `hot${link.rank}`]" v-if="hotJson.title != '历史今天'">{{ link.rank }}</span>
        <el-link :underline="false" :href="link.url" target="_blank" class="link">{{ link.keyword }}</el-link>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { RefreshRight } from '@element-plus/icons-vue'
import { defineEmits, defineProps } from 'vue'
const props = defineProps({
  hotJson: {
    type: Object,
    default: () => {
      return {}
    }
  }
})
const emit = defineEmits(['refresh'])
const refresh = () => {
  emit('refresh', props.hotJson.title)
}
</script>
<style lang="scss" scoped>
.layout-left-module-item {
  position: relative;
  width: 275px;
  height: auto;
  min-height: 100px;
  margin-bottom: 10px;
  background-color: white;
  padding: 10px;
  box-shadow: 0px 0px 20px #cccccc;

  .layout-left-module-item-title {
    line-height: 40px;
    text-align: left;
    font-weight: 600;
    font-size: 14px;

    .el-icon {
      font-size: 13px;
      color: #3d3d3d;
      float: right;
      cursor: pointer;
    }
  }

  .layout-hot-search-result {
    text-align: left;
    line-height: 30px;

    .hot1 {
      font-size: 10px;
      padding: 0px 5px;
      height: 18px;
      line-height: 18px;
      position: relative;
      display: inline-block;
      text-align: center;
      background-color: #ff5722;
      color: #fff;
      border-radius: 2px;
    }

    .hot2 {
      font-size: 10px;
      padding: 0px 5px;
      height: 18px;
      line-height: 18px;
      position: relative;
      display: inline-block;
      text-align: center;
      background-color: #1e9fff;
      color: #fff;
      border-radius: 2px;
    }

    .hot3 {
      font-size: 10px;
      padding: 0px 5px;
      height: 18px;
      line-height: 18px;
      position: relative;
      display: inline-block;
      text-align: center;
      background-color: #ffb800;
      color: #fff;
      border-radius: 2px;
    }

    .hot-search-result-link {
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      word-break: break-all;

      .badge {
        margin-right: 5px;
        font-size: 14px;
      }

      .el-link {
        display: unset;

        ::v-deep .el-link__inner {
          display: unset;
        }
      }
    }
  }
}

@media screen and (max-width: 480px) {
  .layout-left-module-item {
    margin-right: 10px;
  }
}
</style>
